<#-- 
* description: 新增Cron Job的kendoui实现
* version: 1.3
* author:hailin.xu@hand-china.com
-->
<#include "../include/header.html">
    <script src="${base.contextPath}/lib/bootstrap-3.3.7/js/bootstrap.min.js"></script>

<style type="text/css">
    .required {
        font-weight: bold;
    }

    input[readonly="readonly"] {
        background-color: #dedede !important;
    }

    .accept, .status {
        padding-left: 90px;
    }

    .valid {
        color: green;
    }

    .invalid {
        color: red;
    }

    span.k-tooltip {
        margin-left: 6px;
    }
</style>

<body style="padding: 10px">
<div id="messageWindows"></div>

<div id="main-content">
    <ul class="nav nav-tabs" id="mytab">
        <li class="active"><a href="#main-info" data-toggle="tab"><@spring.message "job.infodetail.jobinfo"/></a></li>
        <li class=""><a href="#notify-info" data-toggle="tab"><@spring.message "job.infodetail.notification"/></a></li>
    </ul>
    <div id="tabContent" class="tab-content">
        <div class="tab-pane fade in active" style="margin-top: 20px;" id="main-info">
            <div class="panel-body form-horizontal">
                <div class="form-group required-input">
                    <label class="col-sm-2 control-label"><@spring.message "jobdetaildto.jobname"/></label>
                    <div class="col-sm-4">
                        <input name="jobName" id="jobName" data-role="maskedtextbox" type="text" style="width: 100%" data-bind="value:model.jobName"
                               class="k-textbox" readonly="readonly">

                    </div>
                    <label class="col-sm-2 control-label">
                    <@spring.message "jobdetaildto.jobgroup"/>
                    </label>
                    <div class="col-sm-4">
                        <input name="jobGroup" id="jobGroup" style="width:100%" readonly="readonly" type="text" data-bind="value:model.jobGroup" class="k-textbox">

                    </div>
                </div>

                <div class="form-group required-input">
                    <label class="col-sm-2 control-label">
                    <@spring.message "jobdetaildto.description"/>
                    </label>
                    <div class="col-sm-10">
                        <input id="description" style="width:100%" readonly="readonly" class="k-textbox" data-bind="value:model.description">

                    </div>
                </div>

                <div class="form-group required-input">
                    <label class="col-xs-2 col-sm-2 col-md-2 control-label">
                    <@spring.message "jobdetaildto.jobclassname"/>
                    </label>
                    <div class="col-xs-10 col-sm-10 col-md-10">
                        <input style="width:100%" id="jobClassName" readonly="readonly" name="jobClassName" required type="text" data-bind="value:model.jobClassName" class="k-textbox"/>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-2 col-sm-2 control-label">
                    <@spring.message "triggerdto.starttime"/>
                    </label>
                    <div class="col-xs-4 col-sm-4">
                        <input style="width:100%" id="startTime" readonly="readonly" data-bind="value:model.startTime" class="k-textbox">
                    </div>
                    <label class="col-xs-2 col-sm-2 control-label">
                    <@spring.message "triggerdto.endtime"/>
                    </label>
                    <div class="col-xs-4 col-sm-4">
                        <input style="width:100%" id="endTime" readonly="readonly" data-bind="value:model.endTime" class="k-textbox">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-2 col-sm-2 control-label">
                    <@spring.message "jobrunninginfodto.previousfiretime"/>
                    </label>
                    <div class="col-xs-4 col-sm-4">
                        <input style="width:100%" id="previousFireTime" readonly="readonly" data-bind="value:model.previousFireTime" class="k-textbox">
                    </div>
                    <label class="col-xs-2 col-sm-2 control-label">
                    <@spring.message "jobrunninginfodto.scheduledfiretime"/>
                    </label>
                    <div class="col-xs-4 col-sm-4">
                        <input style="width:100%" class="k-textbox" id="scheduledFireTime" readonly="readonly" data-bind="value:model.scheduledFireTime">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-2 col-sm-2 control-label">
                    <@spring.message "jobrunninginfodto.nextfiretime"/>
                    </label>
                    <div class="col-xs-4 col-sm-4">
                        <input style="width:100%" class="k-textbox"  id="nextFireTime" readonly="readonly" data-bind="value:model.nextFireTime">
                    </div>
                    <label class="col-xs-2 col-sm-2 control-label">
                    <@spring.message "jobrunninginfodto.firetime"/>
                    </label>
                    <div class="col-xs-4 col-sm-4">
                        <input style="width:100%" class="k-textbox" id="fireTime" readonly="readonly" data-bind="value:model.fireTime">
                    </div>
                </div>
                <!-- repeatinterval repeatcount -->
                <div class="form-group required-input" id="repeat">
                    <label class="col-sm-2 control-label">
                        <@spring.message "simpletriggerdto.repeatinterval"/>
                    </label>
                    <div class="col-sm-2">
                        <input name="repeatinterval" class="k-textbox" id="repeatinterval"  readonly="readonly" required style="width:100%" data-bind="value:model.repeatInterval">
                    </div>
                    <label class="col-sm-2 control-label">
                        <@spring.message "simpletriggerdto.repeatcount"/>
                    </label>
                    <div class="col-sm-2">
                        <input style="width:100%" type="text"  readonly="readonly" data-bind="value:model.repeatCount" class="k-textbox">
                    </div>
                    <label class="col-sm-2 control-label">
                        <@spring.message "jobcreatedto.priority"/>
                    </label>
                    <div class="col-sm-2">
                        <input style="width:100%" class="k-textbox" readonly="readonly" data-bind="value:model.triggerPriority">
                    </div>
                </div>
                <!-- repeatinterval repeatcount 结束-->
                <!-- cronExpression -->
                <div class="form-group required-input" id="cron">
                    <label class="col-xs-2 col-sm-2 col-md-2 control-label">
                        <@spring.message "crontriggerdto.cronexpression"/>
                    </label>
                    <div class="col-xs-4 col-sm-4 col-md-4">
                        <input style="width:100%" id="cronExpression" readonly="readonly" name="cronExpression" required class="k-textbox" data-bind="value:model.cronExpression">
                    </div>
                    <label class="col-xs-2 col-sm-2 col-md-2 control-label">
                        <@spring.message "jobcreatedto.priority"/>
                    </label>
                    <div class="col-xs-4 col-sm-4 col-md-4">
                        <input style="width:100%" class="k-textbox"  readonly="readonly" data-bind="value:model.triggerPriority">
                    </div>
                </div>
                <!-- cronExpression结束 -->
                <div id="userAttribute" style="clear: both"></div>

            </div>
        </div>
        <div class="tab-pane fade" style="margin-top: 20px;" id="notify-info">
            <div class="panel-body form-horizontal">
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        <@spring.message "job.infodetail.enable_notification"/>
                    </label>
                    <div class="col-sm-10" style="line-height:27px;">
                        <input id="job_internal_notification" disabled="true"   type="checkbox" data-field="job_internal_notification" data-bind="checked:model.job_internal_notification"/>
                    </div>
                </div>
               <!-- <div class="form-group">
                    <label class="col-sm-2 control-label"><@spring.message "messageemailconfig.accountcode"/>
                    </label>
                    <div class="col-sm-10">
                        <input id="job_internal_email_account" readonly="readonly" name="accountCode" type=text
                               data-bind="value:model.job_internal_email_account"
                               style="width:50%" class="k-textbox"
                        />
                    </div>
                </div>-->
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                    <@spring.message "job.infodetail.email_address"/>
                    </label>
                    <div class="col-sm-10">
                        <input id="job_internal_emailAddress" type="text" data-bind="value:model.job_internal_emailAddress" class="k-textbox" style="width: 50%" readonly="readonly">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"><@spring.message "messagetemplate.templatecode"/>
                    </label>
                    <div class="col-sm-10">
                        <input id="job_internal_email_template" name="templateCode" type=text
                               data-bind="value:model.job_internal_email_template"
                               style="width:50%" readonly="readonly" class="k-textbox"
                        />
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">


    var tempWindowsStatus = 0;

    var viewModel = kendo.observable({
        model: {}
    });
    kendo.bind($('#main-content'), viewModel);
    //当前任务的触发器类型 用来控制显示cron任务内容还是简单任务内容
    var preTriggerType;
    var dataSource = new kendo.data.DataSource({
        transport: {
            //只是创建流程，不需要新建
            read: {
                url: "${base.contextPath}/job/queryInfo",
                type: "POST",
                dataType: "json",
                contentType: "application/json"
            },
            parameterMap: function (options) {
                var jobData = {
                    jobName: "${RequestParameters.jobName}",
                    triggerType: "${RequestParameters.triggerType}",
                    jobGroup: "${RequestParameters.jobGroup}"
                };
                //获取当前任务的触发器类型
                preTriggerType = jobData.triggerType
                return kendo.stringify(jobData);
            }
        },
        requestEnd: function (e) {

            var response = e.response;
            var datas = [];
            $.each(response.rows[0], function (k, v) {
                if (k == 'jobDatas') {
                    $.each(v, function (i, r) {
                        if (r.name == "job_internal_notification" || r.name == "job_internal_emailAddress"
                              || r.name == "job_internal_email_account" || r.name == "job_internal_email_template") {
                            if(r.name == "job_internal_notification"){
                                viewModel.model.set(r.name, r.value=='true'?true:false);
                            }else {
                                viewModel.model.set(r.name, r.value);
                            }
                        } else {
                            datas.push(r);
                        }
                    })
                } else {
                    if(k=='repeatCount' || k=='repeatInterval'){
                        if(k=='repeatCount'){
                            viewModel.model.set(k,v +1);
                        }else if(k=='repeatInterval'){
                            viewModel.model.set(k,v/1000);
                        }
                    }else{
                        viewModel.model.set(k, v);
                    }

                }
            });
            response.rows = datas;
        },
        batch: true,
        schema: {
            data: 'rows',
            total: 'total',
            model: {}
        }
    });

    var userAttributeGrid = $("#userAttribute").kendoGrid({
        dataSource: dataSource,
        height: 156,
        navigatable: false,
        resizable: true,
        scrollable: true,
        columns: [
            //表格的列
            {
                field: "name",
                title: '<@spring.message "job.attributename"/>',
                width: 230
            },
            {
                field: "value",
                title: '<@spring.message "job.attributevalue"/>',
                width: 230
            }
        ]
    }).data("kendoGrid");

   // var tabToActivate = $("#first");
   // $("#tabstrip").kendoTabStrip().data("kendoTabStrip").activateTab(tabToActivate);

    $(document).ready(function () {
        //根据preTriggerType显示任务相应类型属性
        $(function () {
            if (preTriggerType== "SIMPLE") {
                $("#cron").css("display", "none");
            } else if (preTriggerType == "CRON") {
                $("#repeat").css("display", "none");
            }
        });
    });

</script>

</body>